Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable type casting for pow() int arguments #543

Merged
merged 11 commits into from
Sep 18, 2024
Merged

Disable type casting for pow() int arguments #543

merged 11 commits into from
Sep 18, 2024

Conversation

matthiasdiener
Copy link
Collaborator

@matthiasdiener matthiasdiener commented Sep 11, 2024

Fixes (works around?) #542.

cc #538 illinois-ceesd/mirgecom#1055

Please squash

@matthiasdiener matthiasdiener self-assigned this Sep 11, 2024
@matthiasdiener matthiasdiener changed the title Disable arg casting for scalars Disable type casting for scalar arguments Sep 11, 2024
@kaushikcfd
Copy link
Collaborator

Interesting and very strange 😅. Thanks for the diffs. Is the performance dip consistent with different opencl implementations.

@matthiasdiener
Copy link
Collaborator Author

Is the performance dip consistent with different opencl implementations.

Yes, somewhat. With pocl-cuda, there is a ~10%-20% slowdown (see e.g. illinois-ceesd/mirgecom#1055 (comment)). I haven't tried other CL implementations yet.

@matthiasdiener
Copy link
Collaborator Author

This is quite messy, but I think it is ready for a first look @inducer @kaushikcfd

@kaushikcfd
Copy link
Collaborator

LGTM. I don't mind it. (The timings are something of a puzzle... but these changes don't seem to be breaking the CI, so should be fine :))

@matthiasdiener matthiasdiener linked an issue Sep 13, 2024 that may be closed by this pull request
@matthiasdiener matthiasdiener marked this pull request as ready for review September 13, 2024 21:26
@matthiasdiener matthiasdiener changed the title Disable type casting for scalar arguments Disable type casting for pow() int arguments Sep 14, 2024
pytato/utils.py Outdated
import operator
# See https://github.com/inducer/pytato/issues/542
# on why pow() + integers is not typecast to float or complex.
if not ((op == prim.Power or op == operator.pow)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not loving that we're identifying the operator by its callable; that's brittle. (Somebody could just wrap things in a lambda and this would forget what it was doing.)

Copy link
Collaborator Author

@matthiasdiener matthiasdiener Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but I'm not sure how to improve this. Do you have a suggestion?

Edit: add an argument to broadcast_binary_op that identifies it as pow.

pytato/utils.py Show resolved Hide resolved
test/test_codegen.py Outdated Show resolved Hide resolved
@inducer
Copy link
Owner

inducer commented Sep 18, 2024

LGTM. @kaushikcfd?

Copy link
Collaborator

@kaushikcfd kaushikcfd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@inducer inducer enabled auto-merge (squash) September 18, 2024 19:02
@inducer inducer merged commit 5e7d368 into main Sep 18, 2024
11 checks passed
@inducer inducer deleted the fix-arg-cast branch September 18, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type casting of binary op arguments causes kernel slowdowns
3 participants